﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using CompteBancaire;

namespace ApplicationAdmin
{
    class Program
    {
        Administrateur a;
        AccesBD bd = new AccesBD();
        private static UTF8Encoding enc = new UTF8Encoding();

        public Program() { }

        public void quit(string[] args) { Environment.Exit(0); }
        public void help(string[] args)
        {
            Console.WriteLine("help!");
        }
        public void login(string[] args)
        {
            try
            {
                Conseiller c = new Conseiller(bd);
                Utilisateur u;
                c.User = new Utilisateur(1, "foo", "bar", "baz", "zab", "rab", "oof",
                    enc.GetBytes("wut"));
                a = new Administrateur(bd);

                bd.sauverUtilisateur(c.User);
                u = bd.extraireUtilisateur(0);

                Console.WriteLine(u.ToString());
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }

        static void Main(string[] args)
        {
            Program p = new Program();
            Console.Out.WriteLine("Bienvenue dans l'application des administrateurs.\nEntrez \"help\" pour afficher l'aide.");
            do
            {
                MethodInfo m;
                string[] s;
                Console.Out.Write("Commande: ");
                s = Console.In.ReadLine().Split(new char[] { ' ', '\t' });
                m = typeof(Program).GetMethod(s[0]);
                if (m == null)
                {
                    m = typeof(Program).GetMethod("help");
                }
                try
                {
                    m.Invoke(p, new string[][] {s});
                }
                catch (Exception e)
                {
                    Console.WriteLine("invalid arguments"+e.ToString());
                }

            } while (true);
        }
    }
}
